#include "databasemanager.h"
#include <QCoreApplication>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    
    // 创建数据库管理器实例
    DatabaseManager dbManager;
    
    // 初始化数据库
    if (!dbManager.initializeDatabase()) {
        qDebug() << "数据库初始化失败";
        return -1;
    }
    
    // 示例：插入网盘记录
    KmsDisk disk;
    disk.id = "disk_001";
    disk.type = 1;
    disk.name = "我的网盘";
    disk.domainId = "domain_001";
    disk.ownerId = "user_001";
    disk.orderNo = 1;
    
    if (dbManager.insertDisk(disk)) {
        qDebug() << "网盘记录插入成功";
    } else {
        qDebug() << "网盘记录插入失败";
    }
    
    // 示例：查询网盘记录
    QList<KmsDisk> disks = dbManager.queryDisksByName("我的网盘");
    qDebug() << "查询到" << disks.size() << "个网盘记录";
    for (const auto &d : disks) {
        qDebug() << "网盘ID:" << d.id << "名称:" << d.name;
    }
    
    // 示例：插入文件夹记录
    KmsFolder folder;
    folder.id = "folder_001";
    folder.name = "文档";
    folder.diskId = "disk_001";
    folder.folderId = "";
    folder.path = "/我的网盘/文档";
    folder.creator = "admin";
    folder.creatorId = "user_001";
    folder.type = 1;
    folder.createDate = "2024-01-01 10:00:00";
    folder.lastModifyDate = "2024-01-01 10:00:00";
    folder.orderNo = 1;
    folder.removeOperator = "";
    
    if (dbManager.insertFolder(folder)) {
        qDebug() << "文件夹记录插入成功";
    } else {
        qDebug() << "文件夹记录插入失败";
    }
    
    // 示例：查询文件夹记录
    QList<KmsFolder> folders = dbManager.queryFoldersByPath("/我的网盘");
    qDebug() << "查询到" << folders.size() << "个文件夹记录";
    for (const auto &f : folders) {
        qDebug() << "文件夹ID:" << f.id << "名称:" << f.name << "路径:" << f.path;
    }
    
    // 示例：插入文件记录
    KmsFile file;
    file.id = "file_001";
    file.name = "测试文档.txt";
    file.diskId = "disk_001";
    file.folderId = "folder_001";
    file.path = "/我的网盘/文档/测试文档.txt";
    file.creator = "admin";
    file.creatorId = "user_001";
    file.type = "txt";
    file.createDate = "2024-01-01 10:30:00";
    file.lastModifyDate = "2024-01-01 10:30:00";
    file.originType = 1;
    file.originId = "origin_001";
    file.url = "http://example.com/file/001";
    file.dimension = 1024;
    file.collects = 0;
    file.shares = 0;
    file.views = 0;
    file.downloads = 0;
    file.lastDownloadDate = "";
    file.lastCollectDate = "";
    file.lastShareDate = "";
    file.lastViewDate = "";
    file.lastEditDate = "";
    file.good = 0;
    file.bad = 0;
    file.categorys = "文档";
    file.categorysJson = "{\"type\":\"document\"}";
    file.removeOperator = "";
    
    if (dbManager.insertFile(file)) {
        qDebug() << "文件记录插入成功";
    } else {
        qDebug() << "文件记录插入失败";
    }
    
    // 示例：查询文件记录
    QList<KmsFile> files = dbManager.queryFilesByPath("/我的网盘/文档");
    qDebug() << "查询到" << files.size() << "个文件记录";
    for (const auto &f : files) {
        qDebug() << "文件ID:" << f.id << "名称:" << f.name << "路径:" << f.path;
    }
    
    qDebug() << "数据库操作示例完成";
    
    return 0;
}
